package com.htandroid.htandroid.webservice;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;


import android.util.Xml;

import com.htandroid.htandroid.entity.GcwxList;
import com.htandroid.htandroid.tools.ToolLog;

public class XMLGcwxVouchlist {

    /**
     * 解析评论xml信息
     *
     * @param result
     * @return
     */
    public static ArrayList<GcwxList> paraseCommentInfors(String result) {
        ArrayList<GcwxList> list = new ArrayList<GcwxList>();
        //字符转换成字节流
        InputStream inputStream = new ByteArrayInputStream(result.getBytes());
        XmlPullParser parser = Xml.newPullParser();

        try {
            parser.setInput(inputStream, "UTF-8");
            int eventType = parser.getEventType();
            GcwxList info = new GcwxList();

            while (eventType != XmlPullParser.END_DOCUMENT) {
                switch (eventType) {
                    case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
                        break;
                    case XmlPullParser.START_TAG:// 开始元素事件
                        String name = parser.getName();
                        if (name.equalsIgnoreCase("GcwxList")) {
                            info = new GcwxList();
                        } else {
                            eventType = parser.next();
                            if (name.equalsIgnoreCase("cvouchid")) {
                                info.setCvouchid(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("Id")) {
                                info.setID(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ddate")) {
                                info.setDdate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("dqdate")) {
                                info.setDqdate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdepcode")) {
                                info.setCdepcode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdepname")) {
                                info.setCdepname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cwxplcode")) {
                                info.setCwxplcode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cwxplname")) {
                                info.setCwxplname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cmaker")) {
                                info.setCmaker(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cbxtext")) {
                                info.setCbxtext(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("bpressing")) {
                                info.setBpressing(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cjder")) {
                                info.setCjder(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("djddate")) {
                                info.setDjddate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cwxgcode")) {
                                info.setCwxgcode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cwxgname")) {
                                info.setCwxgname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cwxpcode")) {
                                info.setCwxpcode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cwxpname")) {
                                info.setCwxpname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("dwcdate")) {
                                info.setDwcdate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("dxddate")) {
                                info.setDxddate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cxder")) {
                                info.setCxder(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cchecker")) {
                                info.setCchecker(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("dckdate")) {
                                info.setDckdate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cresult")) {
                                info.setCresult(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cmemo")) {
                                info.setCmemo(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdjcode")) {
                                info.setCdjcode(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cdjname")) {
                                info.setCdjname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("csuspender")) {
                                info.setCsuspender(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("csuspendreason")) {
                                info.setCsuspendreason(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("dsuspenddate")) {
                                info.setDsuspenddate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ctype")) {
                                info.setCtype(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ctypename")) {
                                info.setCtypename(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("printsend")) {
                                info.setPrintsend(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("printsendname")) {
                                info.setPrintsendname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("xzwxnames")) {
                                info.setXzwxnames(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("xzwxcodes")) {
                                info.setXzwxcodes(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("eswxdate")) {
                                info.setEswxdate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("planvouchid")) {
                                info.setPlanvouchid(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("plandate")) {
                                info.setPlandate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("checkmemo")) {
                                info.setCheckmemo(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("isndjz")) {
                                info.setIsndjz(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cstatus")) {
                                info.setCstatus(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("sucstatus")) {
                                info.setSucstatus(string2null(parser.getText()));
                            }
                        }
                        break;
                    case XmlPullParser.END_TAG:// 结束元素事件
                        if (parser.getName().equalsIgnoreCase("GcwxList")) {
                            list.add(info);
                            info = null;
                        }
                        break;
                }
                eventType = parser.next();
            }
            inputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }
}
